using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using DL;
/// <summary>
/// Summary description for NewsDAL
/// </summary>
namespace DAL 
{
    
    public class NewsDAL  : BaseDAL
    {
    	#region Private Variables

		#endregion
		
 #region Public Constructors
        public NewsDAL()
        {
            //
            // TODO: Add constructor logic here
            //
            
        }
 #endregion       

	
		
#region Public Methods
        public int Insert(NewsDL objNewsDL)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "News_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Title", SqlDbType.NVarChar);
Sqlparam.Value = objNewsDL.Title;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Avatar", SqlDbType.NVarChar);
Sqlparam.Value = objNewsDL.Avatar;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Description", SqlDbType.NText);
Sqlparam.Value = objNewsDL.Description;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Tag", SqlDbType.NVarChar);
Sqlparam.Value = objNewsDL.Tag;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Content", SqlDbType.NText);
Sqlparam.Value = objNewsDL.Content;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@CreateTime", SqlDbType.DateTime);
Sqlparam.Value = objNewsDL.CreateTime;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@ModifyTime", SqlDbType.DateTime);
Sqlparam.Value = objNewsDL.ModifyTime;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@UserCreate", SqlDbType.Int);
Sqlparam.Value = objNewsDL.UserCreate;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Note", SqlDbType.NText);
Sqlparam.Value = objNewsDL.Note;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@View", SqlDbType.Int);
Sqlparam.Value = objNewsDL.View;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@StatusId", SqlDbType.Int);
Sqlparam.Value = objNewsDL.StatusId;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@NewsViewMore", SqlDbType.Bit);
Sqlparam.Value = objNewsDL.NewsViewMore;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@NewsHot", SqlDbType.Bit);
Sqlparam.Value = objNewsDL.NewsHot;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@NewsPromotion", SqlDbType.Bit);
Sqlparam.Value = objNewsDL.NewsPromotion;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@NewsNew", SqlDbType.Bit);
Sqlparam.Value = objNewsDL.NewsNew;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Order", SqlDbType.Int);
Sqlparam.Value = objNewsDL.Order;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
Sqlparam.Direction = ParameterDirection.ReturnValue;
Sqlcomm.Parameters.Add(Sqlparam);

           
            int result =base.ExecuteNoneQuery(Sqlcomm);
            
            if(!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
				result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(NewsDL objNewsDL)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "News_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Id", SqlDbType.Int);
Sqlparam.Value = objNewsDL.Id;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Title", SqlDbType.NVarChar);
Sqlparam.Value = objNewsDL.Title;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Avatar", SqlDbType.NVarChar);
Sqlparam.Value = objNewsDL.Avatar;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Description", SqlDbType.NText);
Sqlparam.Value = objNewsDL.Description;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Tag", SqlDbType.NVarChar);
Sqlparam.Value = objNewsDL.Tag;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Content", SqlDbType.NText);
Sqlparam.Value = objNewsDL.Content;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@CreateTime", SqlDbType.DateTime);
Sqlparam.Value = objNewsDL.CreateTime;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@ModifyTime", SqlDbType.DateTime);
Sqlparam.Value = objNewsDL.ModifyTime;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@UserCreate", SqlDbType.Int);
Sqlparam.Value = objNewsDL.UserCreate;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Note", SqlDbType.NText);
Sqlparam.Value = objNewsDL.Note;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@View", SqlDbType.Int);
Sqlparam.Value = objNewsDL.View;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@StatusId", SqlDbType.Int);
Sqlparam.Value = objNewsDL.StatusId;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@NewsViewMore", SqlDbType.Bit);
Sqlparam.Value = objNewsDL.NewsViewMore;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@NewsHot", SqlDbType.Bit);
Sqlparam.Value = objNewsDL.NewsHot;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@NewsPromotion", SqlDbType.Bit);
Sqlparam.Value = objNewsDL.NewsPromotion;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@NewsNew", SqlDbType.Bit);
Sqlparam.Value = objNewsDL.NewsNew;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Order", SqlDbType.Int);
Sqlparam.Value = objNewsDL.Order;
Sqlcomm.Parameters.Add(Sqlparam);


            
            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);
            
            int result=base.ExecuteNoneQuery(Sqlcomm);
            
             if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);
                
            return result;

           
        }

        public int Delete(NewsDL objNewsDL)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "News_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@Id", SqlDbType.Int);
Sqlparam.Value = objNewsDL.Id;
Sqlcomm.Parameters.Add(Sqlparam);


            
            int result=base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

         public int DeleteAll()
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "News_DeleteAll";

            int result=base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public NewsDL Select(NewsDL objNewsDL)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "News_GetByPK";
            SqlParameter Sqlparam;
  

            Sqlparam = new SqlParameter("@Id", SqlDbType.Int);
Sqlparam.Value = objNewsDL.Id;
Sqlcomm.Parameters.Add(Sqlparam);


            
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if(!Convert.IsDBNull(dr["Id"]))
objNewsDL.Id=Convert.ToInt32(dr["Id"]);
if(!Convert.IsDBNull(dr["Title"]))
objNewsDL.Title=Convert.ToString(dr["Title"]);
if(!Convert.IsDBNull(dr["Avatar"]))
objNewsDL.Avatar=Convert.ToString(dr["Avatar"]);
if(!Convert.IsDBNull(dr["Description"]))
objNewsDL.Description=Convert.ToString(dr["Description"]);
if(!Convert.IsDBNull(dr["Tag"]))
objNewsDL.Tag=Convert.ToString(dr["Tag"]);
if(!Convert.IsDBNull(dr["Content"]))
objNewsDL.Content=Convert.ToString(dr["Content"]);
if(!Convert.IsDBNull(dr["CreateTime"]))
objNewsDL.CreateTime=Convert.ToDateTime(dr["CreateTime"]);
if(!Convert.IsDBNull(dr["ModifyTime"]))
objNewsDL.ModifyTime=Convert.ToDateTime(dr["ModifyTime"]);
if(!Convert.IsDBNull(dr["UserCreate"]))
objNewsDL.UserCreate=Convert.ToInt32(dr["UserCreate"]);
if(!Convert.IsDBNull(dr["Note"]))
objNewsDL.Note=Convert.ToString(dr["Note"]);
if(!Convert.IsDBNull(dr["View"]))
objNewsDL.View=Convert.ToInt32(dr["View"]);
if(!Convert.IsDBNull(dr["StatusId"]))
objNewsDL.StatusId=Convert.ToInt32(dr["StatusId"]);
if(!Convert.IsDBNull(dr["NewsViewMore"]))
objNewsDL.NewsViewMore=Convert.ToBoolean(dr["NewsViewMore"]);
if(!Convert.IsDBNull(dr["NewsHot"]))
objNewsDL.NewsHot=Convert.ToBoolean(dr["NewsHot"]);
if(!Convert.IsDBNull(dr["NewsPromotion"]))
objNewsDL.NewsPromotion=Convert.ToBoolean(dr["NewsPromotion"]);
if(!Convert.IsDBNull(dr["NewsNew"]))
objNewsDL.NewsNew=Convert.ToBoolean(dr["NewsNew"]);
if(!Convert.IsDBNull(dr["Order"]))
objNewsDL.Order=Convert.ToInt32(dr["Order"]);

            }
             return objNewsDL;
        }

        public ArrayList SelectAll1( )
        {
			
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "News_GetAll";
            
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrNewsDL = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach(DataRow dr in dt.Rows)
{
NewsDL objNewsDL= new NewsDL();
if(!Convert.IsDBNull(dr["Id"]))
objNewsDL.Id=Convert.ToInt32(dr["Id"]);
if(!Convert.IsDBNull(dr["Title"]))
objNewsDL.Title=Convert.ToString(dr["Title"]);
if(!Convert.IsDBNull(dr["Avatar"]))
objNewsDL.Avatar=Convert.ToString(dr["Avatar"]);
if(!Convert.IsDBNull(dr["Description"]))
objNewsDL.Description=Convert.ToString(dr["Description"]);
if(!Convert.IsDBNull(dr["Tag"]))
objNewsDL.Tag=Convert.ToString(dr["Tag"]);
if(!Convert.IsDBNull(dr["Content"]))
objNewsDL.Content=Convert.ToString(dr["Content"]);
if(!Convert.IsDBNull(dr["CreateTime"]))
objNewsDL.CreateTime=Convert.ToDateTime(dr["CreateTime"]);
if(!Convert.IsDBNull(dr["ModifyTime"]))
objNewsDL.ModifyTime=Convert.ToDateTime(dr["ModifyTime"]);
if(!Convert.IsDBNull(dr["UserCreate"]))
objNewsDL.UserCreate=Convert.ToInt32(dr["UserCreate"]);
if(!Convert.IsDBNull(dr["Note"]))
objNewsDL.Note=Convert.ToString(dr["Note"]);
if(!Convert.IsDBNull(dr["View"]))
objNewsDL.View=Convert.ToInt32(dr["View"]);
if(!Convert.IsDBNull(dr["StatusId"]))
objNewsDL.StatusId=Convert.ToInt32(dr["StatusId"]);
if(!Convert.IsDBNull(dr["NewsViewMore"]))
objNewsDL.NewsViewMore=Convert.ToBoolean(dr["NewsViewMore"]);
if(!Convert.IsDBNull(dr["NewsHot"]))
objNewsDL.NewsHot=Convert.ToBoolean(dr["NewsHot"]);
if(!Convert.IsDBNull(dr["NewsPromotion"]))
objNewsDL.NewsPromotion=Convert.ToBoolean(dr["NewsPromotion"]);
if(!Convert.IsDBNull(dr["NewsNew"]))
objNewsDL.NewsNew=Convert.ToBoolean(dr["NewsNew"]);
if(!Convert.IsDBNull(dr["Order"]))
objNewsDL.Order=Convert.ToInt32(dr["Order"]);
arrNewsDL.Add(objNewsDL);
}
            }
               return arrNewsDL;
        }
        
        public DataTable SelectAll( )
        {
			
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "News_GetAll";
            
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
          
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                
            }
               return dt;
        }

     
#endregion          
    
    }

}
